{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "38454d92",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                  Model    Dataset  Accuracy  F1 Score    TP   FN   FP    TN\n",
      "0      Basic FNN No FFT      Basic    0.9833    0.9539  4815   67   32  1024\n",
      "1      Basic FNN No FFT  CDD-based    0.9248    0.8739  4168  357  115  1635\n",
      "2      Basic FNN No FFT   External    0.8287    0.7237  3347  840  109  1243\n",
      "3  CDD-based FNN No FFT      Basic    0.9828    0.9515  4835   47   55  1001\n",
      "4  CDD-based FNN No FFT  CDD-based    0.9388    0.8923  4300  225  159  1591\n"
     ]
    }
   ],
   "source": [
    "import re\n",
    "import pandas as pd\n",
    "\n",
    "# --- Step 1: Load raw content from files ---\n",
    "with open(\"fnn_no_fft.txt\", \"r\") as f:\n",
    "    no_fft_data = f.read()\n",
    "\n",
    "with open(\"fnn_with_fft.txt\", \"r\") as f:\n",
    "    with_fft_data = f.read()\n",
    "\n",
    "# --- Step 2: Define helper to normalise dataset names ---\n",
    "def standardise_dataset_name(name):\n",
    "    name = name.replace(\"test\", \"\").strip().lower()\n",
    "    if \"basic\" in name:\n",
    "        return \"Basic\"\n",
    "    elif \"cdd\" in name:\n",
    "        return \"CDD-based\"\n",
    "    elif \"external\" in name:\n",
    "        return \"External\"\n",
    "    else:\n",
    "        return name.capitalize()\n",
    "\n",
    "# --- Step 3: Define parser function ---\n",
    "def extract_entries(raw_text, model_label):\n",
    "    results = []\n",
    "    pattern = re.compile(\n",
    "        r\"Result of (.*?) on (.*?) dataset\\nAccuracy: ([\\d.]+)\\nF1 score: ([\\d.]+)\\n(\\d+) (\\d+)\\n(\\d+) (\\d+)\"\n",
    "    )\n",
    "    for match in pattern.finditer(raw_text):\n",
    "        model_type, dataset, acc, f1, tp, fn, fp, tn = match.groups()\n",
    "        dataset_name = standardise_dataset_name(dataset)\n",
    "        if \"basic\" in model_type.lower() and \"pattern\" not in model_type.lower():\n",
    "            model_name = f\"Basic FNN {model_label}\"\n",
    "        elif \"pattern\" in model_type.lower():\n",
    "            model_name = f\"CDD-based FNN {model_label}\"\n",
    "        elif \"cdd-based\" in model_type.lower():\n",
    "            model_name = f\"CDD-based FNN {model_label}\"\n",
    "        else:\n",
    "            continue  # Skip unknown model types\n",
    "        results.append({\n",
    "            \"Model\": model_name,\n",
    "            \"Dataset\": dataset_name,\n",
    "            \"Accuracy\": float(acc),\n",
    "            \"F1 Score\": float(f1),\n",
    "            \"TP\": int(tp),\n",
    "            \"FN\": int(fn),\n",
    "            \"FP\": int(fp),\n",
    "            \"TN\": int(tn),\n",
    "        })\n",
    "    return results\n",
    "\n",
    "# --- Step 4: Parse both files ---\n",
    "results_no_fft = extract_entries(no_fft_data, \"No FFT\")\n",
    "results_with_fft = extract_entries(with_fft_data, \"With FFT\")\n",
    "\n",
    "# --- Step 5: Combine into DataFrame ---\n",
    "all_results = results_no_fft + results_with_fft\n",
    "df_results = pd.DataFrame(all_results)\n",
    "\n",
    "# --- Step 6: Export (optional) ---\n",
    "df_results.to_csv(\"inference_results.csv\", index=False)\n",
    "\n",
    "# --- Step 7: Display a preview ---\n",
    "print(df_results.head())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
